/** EasyWeb iframe v3.1.4 date:2019-08-05 License By http://easyweb.vip */
// 以下代码是配置layui扩展模块的目录，每个页面都需要引入
var os, vm;
layui.config({
    version: false,
    base: '/scripts/libs/module/'
}).extend({
    formSelects: 'formSelects/formSelects-v4',
    treetable: 'treetable-lay/treetable',
    dropdown: 'dropdown/dropdown',
    notice: 'notice/notice',
    step: 'step-lay/step',
    dtree: 'dtree/dtree',
    citypicker: 'city-picker/city-picker',
    tableSelect: 'tableSelect/tableSelect',
    Cropper: 'Cropper/Cropper',
    zTree: 'zTree/zTree',
    introJs: 'introJs/introJs',
    fileChoose: 'fileChoose/fileChoose',
    tagsInput: 'tagsInput/tagsInput',
    Drag: 'Drag/Drag',
    CKEDITOR: 'ckeditor/ckeditor',
    Split: 'Split/Split',
    cascader: 'cascader/cascader',
    iconPicker: 'iconPicker/iconPicker',
    fonticonpicker: 'iconPicker/fonticonpicker',
    linedtextarea: 'linedtextarea/linedtextarea',//textarea高亮
    webuploader: 'uploader/webuploader',//上传
    tip: 'tip/tip',//气泡
    DPlayer: 'DPlayer/DPlayer',//DPlayer视频播放器
    validform: 'validform/validform'//验证
}).use(['cmswh', 'layer', 'admin'], function () {
    var layer = layui.layer, admin = layui.admin, $ = layui.jquery;
    os = layui.cmswh;

    // 移除loading动画
    setTimeout(function () {
        admin.removeLoading();
    }, window == top ? 600 : 100);
    
    $(".imglist").ruleLayoutImgList();
    $(".layui-tab").layerFloat();
    $("#floatHead").smartFloat();
    
    //窗口尺寸改变时
    $(window).resize(function () {
        //延迟执行,防止多次触发
        setTimeout(function () {
            $(".imglist").ruleLayoutImgList();
        }, 200);
    });

    //执行后台输出的JS代码
    function BagClientScript() {
        try {
            var clientScript = $("#ClientScript").html();
            if (clientScript != "") {
                var func = new Function(clientScript);
                func();
            }
        } catch (e) {
            console.log("语句错误：" + e.message);
        }
    }
    BagClientScript();
});

/*获取URL指定参数值。*/
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}

/*类似于string.Format的用法*/
function stringFormat() {
    if (arguments.length == 0)
        return null;
    var str = arguments[0];
    for (var i = 1; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        var strargument = (arguments[i] == "undefined") ? "" : arguments[i];
        str = str.replace(re, strargument);
    }
    return str;
}

/*只允许输入小数*/
function checkForFloat(obj, e) {
    var isOK = false;
    var key = window.event ? e.keyCode : e.which;
    if ((key > 95 && key < 106) || //小键盘上的0到9  
        (key > 47 && key < 60) ||  //大键盘上的0到9  
        (key == 110 && obj.value.indexOf(".") < 0) || //小键盘上的.而且以前没有输入.  
        (key == 190 && obj.value.indexOf(".") < 0) || //大键盘上的.而且以前没有输入.  
        key == 8 || key == 9 || key == 46 || key == 37 || key == 39) {
        isOK = true;
    } else {
        if (window.event) { //IE
            e.returnValue = false;   //event.returnValue=false 效果相同.    
        } else { //Firefox 
            e.preventDefault();
        }
    }
    return isOK;
}

/*只允许输入数字*/
function checkNumber(e) {
    var keynum = window.event ? e.keyCode : e.which;
    if ((48 <= keynum && keynum <= 57) || (96 <= keynum && keynum <= 105) || keynum == 8) {
        return true;
    } else {
        return false;
    }
}

$.fn.extend({
    /*智能浮动层函数*/
    smartFloat: function () {
        var position = function (element) {
            var obj = element;
            var top = obj.position().top;
            var pos = obj.css("position");
            $(window).scroll(function () {
                var scrolls = $(this).scrollTop();
                if (scrolls > top) {
                    obj.width(element.width());
                    if (window.XMLHttpRequest) {
                        obj.css({
                            position: "fixed",
                            top: 0,
                            left: 16
                        });
                    } else {
                        obj.css({
                            top: scrolls
                        });
                    }
                } else {
                    obj.css({
                        position: pos,
                        top: 0,
                        left: 0
                    });
                }
            });
        };
        return $(this).each(function () {
            position($(this));
        });
    },
    /*初始化Tree目录事件*/
    initCategoryTree: function (isOpen) {
        var fCategoryTree = function (parentObj) {
            //遍历所有的UL
            parentObj.find("ul").each(function (i) {
                //遍历UL第一层LI
                $(this).children("li").each(function () {
                    var liObj = $(this);
                    //判断是否有子菜单和设置距左距离
                    var parentIconLenght = liObj.parent().parent().children(".tbody").children(".index").children(".icon").length; //父节点的左距离
                    var indexObj = liObj.children(".tbody").children(".index"); //需要树型的目录列
                    //设置左距离
                    if (parentIconLenght == 0) {
                        parentIconLenght = 1;
                    }
                    for (var n = 0; n <= parentIconLenght; n++) { //注意<=
                        $('<i class="icon"></i>').prependTo(indexObj); //插入到index前面
                    }
                    //设置按钮和图标
                    indexObj.children(".icon").last().addClass("iconfont icon-folder1"); //设置最后一个图标
                    //如果有下级菜单
                    if (liObj.children("ul").length > 0) {
                        //如果要求全部展开
                        if (isOpen) {
                            indexObj.children(".icon").eq(-2).addClass("expandable iconfont icon-open"); //设置图标展开状态
                        } else {
                            indexObj.children(".icon").eq(-2).addClass("expandable iconfont icon-close1"); //设置图标闭合状态
                            liObj.children("ul").hide(); //隐藏下级的UL
                        }
                        //绑定单击事件
                        indexObj.children(".expandable").click(function () {
                            //如果菜单已展开则闭合
                            if ($(this).hasClass("icon-open")) {
                                //设置自身的右图标为+号
                                $(this).removeClass("icon-open");
                                $(this).addClass("icon-close1");
                                //隐藏自身父节点的UL子菜单
                                $(this).parent().parent().parent().children("ul").slideUp(300);
                            } else {
                                //设置自身的右图标为-号
                                $(this).removeClass("icon-close1");
                                $(this).addClass("icon-open");
                                //显示自身父节点的UL子菜单
                                $(this).parent().parent().parent().children("ul").slideDown(300);
                            }
                        });
                    } else {
                        indexObj.children(".icon").eq(-2).addClass("iconfont icon-csac");
                    }
                });
                //显示第一个UL
                if (i == 0) {
                    $(this).show();
                    //展开第一个菜单
                    if ($(this).children("li").first().children("ul").length > 0) {
                        $(this).children("li").first().children(".tbody").children(".index").children(".expandable").removeClass("icon-close1");
                        $(this).children("li").first().children(".tbody").children(".index").children(".expandable").addClass("icon-open");
                        $(this).children("li").first().children("ul").show();
                    }
                }
            });
        };
        return $(this).each(function () {
            fCategoryTree($(this));
        });
    },
    layerFloat: function () {
        $(".layui-tab li").click(function () {
            var index = $(".layui-tab li").index(this);
            $(this).parent().children("li").removeClass("layui-this");
            $(this).addClass("layui-this");
            $(".layui-tab-content").children(".layui-tab-item").removeClass("layui-show");
            $(".layui-tab-content .layui-tab-item").eq(index).addClass("layui-show");
        })
    },
    /*日期控件*/
    ruleDateInput: function () {
        var dateInput = function (parentObj) {
            parentObj.wrap('<div class="date-input"></div>');
            parentObj.before('<i class="iconfont icon-date"></i>');
        };
        return $(this).each(function () {
            dateInput($(this));
        });
    },
    autoCheckbox: function () {
        var option = {
            hd: ".core",
            bd: ".pannel"
        };
        var coreCheckbox = function (obj) {
            //绑定初始状态
            curDisplay(obj, obj.find(option.hd).find('input[type="checkbox"]').is(':checked'));
            //绑定事件
            obj.find('.layui-form-checkbox').on('click', function () {
                curDisplay(obj, obj.find(option.hd).find('input[type="checkbox"]').is(':checked'));
            });
        };
        function curDisplay(obj, isShow) {
            if (isShow) {
                obj.find(option.bd).show();
            } else {
                obj.find(option.bd).hide();
            }
        };
        return $(this).each(function () {
            coreCheckbox($(this));
        });
    },
    /*智能浮动层函数*/
    autoSelect: function (option) {
        option = $.extend({}, {
            hd: ".core",
            bd: ".pannel .box"
        }, option);
        var coreSelect = function (obj) {
            curDisplay(obj);
            //绑定事件
            obj.find(option.hd).find('.layui-form-radio').on('click', function () {
                curDisplay(obj);
            });
        };
        function curDisplay(obj) {
            var radio = obj.find(option.hd).find('input[type="radio"]');
            radio.each(function (i) {
                var isShow = $(this).is(':checked');
                if (isShow) {
                    obj.find(option.bd).eq(i).show().siblings().hide();
                }
            })
        }
        return $(this).each(function () {
            coreSelect($(this));
        });
    },
    /*图文列表排列响应式*/
    ruleLayoutImgList: function () {
        var fun = function (parentObj) {
            var divWidth = parentObj.width();
            var liSpace = parseFloat(parentObj.find("ul li").css("margin-left"));
            var rankCount = Math.floor((divWidth + liSpace) / 230);
            var liWidth = ((divWidth + liSpace) / rankCount) - liSpace;
            parentObj.find("ul li").width(liWidth);
        };
        return $(this).each(function () {
            fun($(this));
        });
    }
});
//写Cookie
function addCookie(objName, objValue, objHours) {
    var str = objName + "=" + escape(objValue);
    if (objHours > 0) {//为0时不设定过期时间，浏览器关闭时cookie自动消失
        var date = new Date();
        var ms = objHours * 3600 * 1000;
        date.setTime(date.getTime() + ms);
        str += "; expires=" + date.toGMTString();
    }
    document.cookie = str;
}

//读Cookie
function getCookie(objName) {//获取指定名称的cookie的值
    var arrStr = document.cookie.split("; ");
    for (var i = 0; i < arrStr.length; i++) {
        var temp = arrStr[i].split("=");
        if (temp[0] == objName) {
            if (temp.length == 3) {
                return unescape(temp[2]);
            }
            else {
                return unescape(temp[1]);
            }
        }
    }
    return "";
}
//清除cookie  
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null) {
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
    }
}